package com.netistate.dao;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.netistate.base.BaseDao;
import com.netistate.pojo.User;
import com.netistate.util.GetMd5;

@Repository
public class UserDao extends BaseDao<User, Integer>{

	/**
	 * 鐧诲綍楠岃瘉
	 * @param user
	 * @return
	 */
	public User findUserByUsernameAndPwd(User user) {
		String hql = "from User where username=? and password=?";
		Query query = getSession().createQuery(hql);
		query.setString(0, user.getUsername());
		query.setString(1, GetMd5.getMd5(user.getPassword()));
		
		return (User) query.uniqueResult();
	}

	/**
	 * 根据username去找user
	 * @param projectManager
	 * @return
	 */
	public User findUserByUsername(String projectManager) {
		String hql = "from User where username=?";
		Query query = getSession().createQuery(hql);
		query.setString(0, projectManager);
		User u = (User) query.uniqueResult();
		return u;
	}

}
